package com.ydkj.a37e_mall.Classes.Fragment;

import android.app.Activity;
import android.content.Context;
import android.content.Intent;
import android.graphics.Paint;
import android.os.Bundle;
import android.support.annotation.Nullable;
import android.util.Log;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.BaseAdapter;
import android.widget.GridView;
import android.widget.ImageView;
import android.widget.LinearLayout;
import android.widget.RelativeLayout;
import android.widget.ScrollView;
import android.widget.TextView;

import com.github.wanglu1209.bannerlibrary.Banner;
import com.github.wanglu1209.bannerlibrary.BannerPagerAdapter;
import com.handmark.pulltorefresh.library.PullToRefreshBase;
import com.handmark.pulltorefresh.library.PullToRefreshScrollView;
import com.loopj.android.http.JsonHttpResponseHandler;
import com.loopj.android.http.RequestParams;
import com.nostra13.universalimageloader.core.ImageLoader;
import com.ydkj.a37e_mall.Classes.Acitivity.BaseActivity.ActivityWebView;
import com.ydkj.a37e_mall.Classes.Acitivity.BaseActivity.AllProduct;
import com.ydkj.a37e_mall.Classes.Acitivity.BaseActivity.HotProduct;
import com.ydkj.a37e_mall.Classes.Acitivity.BaseActivity.LoginActivity;
import com.ydkj.a37e_mall.Classes.Acitivity.BaseActivity.MipcaActivityCapture;
import com.ydkj.a37e_mall.Classes.Acitivity.BaseActivity.MyTbActivity;
import com.ydkj.a37e_mall.Classes.Acitivity.BaseActivity.NewProductShelves;
import com.ydkj.a37e_mall.Classes.Acitivity.BaseActivity.ProductDetails;
import com.ydkj.a37e_mall.Classes.Acitivity.BaseActivity.RecommendActivity;
import com.ydkj.a37e_mall.Classes.Acitivity.BaseActivity.Search;
import com.ydkj.a37e_mall.Classes.Acitivity.BaseActivity.SortSlidingActivity;
import com.ydkj.a37e_mall.Classes.Acitivity.BaseActivity.SpecialProduct;
import com.ydkj.a37e_mall.Classes.Applicatiom.MyApplication;
import com.ydkj.a37e_mall.Classes.Model.Request.ActivitytypeReq;
import com.ydkj.a37e_mall.Classes.Model.Request.AllProductReq;
import com.ydkj.a37e_mall.Classes.Model.Request.HomePageBannerReq;
import com.ydkj.a37e_mall.Classes.Model.Request.HomepageDataReq;
import com.ydkj.a37e_mall.Classes.Model.Response.ActivitytypeResp;
import com.ydkj.a37e_mall.Classes.Model.Response.AllProductResp;
import com.ydkj.a37e_mall.Classes.Model.Response.BannerInfoResp;
import com.ydkj.a37e_mall.Classes.Model.Response.FangGeResp;
import com.ydkj.a37e_mall.Classes.Model.Response.HomepageDataResp;
import com.ydkj.a37e_mall.Classes.Model.Response.NoticeADResp;
import com.ydkj.a37e_mall.R;
import com.ydkj.a37e_mall.Resource.Utils.Async_http_get;
import com.ydkj.a37e_mall.Resource.Utils.CommonUtil;
import com.ydkj.a37e_mall.Resource.Utils.Const;
import com.ydkj.a37e_mall.Resource.Utils.GsonImpl;
import com.ydkj.a37e_mall.Resource.Utils.SharedPreferencesUtil;
import com.ydkj.a37e_mall.Resource.View.CustomProgressDialog;

import org.json.JSONObject;

import java.util.ArrayList;
import java.util.List;

import cn.sharesdk.framework.ShareSDK;
import cz.msebera.android.httpclient.Header;

import static android.app.Activity.RESULT_OK;
import static com.ydkj.a37e_mall.R.mipmap.scan;


/**
 * Created by Administrator on 2017/1/4.
 */

public class HomePageFg extends BaseFg implements View.OnClickListener {
    private View rootView;
    private Activity mActivity;
    //    public SlidingMenu mSlidingMenu;
    private SharedPreferencesUtil sharedPreferencesUtil;
    private MyApplication myApplication;
    private PullToRefreshScrollView homepage_ptrScrollview;
    private List<HomepageDataResp.ResultEntity.DataEntity> homepage_productList;
    private List<BannerInfoResp.ResultEntity.DataEntity> bannerList;
    private List<AllProductResp.ResultEntity.DataEntity> all_productList;

    private ScrollView hearderViewLayout;
    private Banner banner;
    private ImageView scan_img, classification_img, search_img;

    private LinearLayout lly_title_bar, lly_et_search;
    private ImageView lly_img_search;
    private LinearLayout lly_hand_gift, lly_cat, lly_dog, lly_overseas_buy;
    private ImageView img_top_product1, img_top_product2, img_top_product3, img_top_product4, img_top_product5;
    private RelativeLayout rly_new_product_shelves, rly_hot_product, rly_special_product, rly_integral_product;
    private ImageView img_new_product_shelves_big, img_new_product1, img_new_product2, img_new_product3, img_new_product4, img_new_product5, img_new_product6;
    private RelativeLayout rly_classification, rly_scan;

    //特价产品
    private LinearLayout lly_new_product1, lly_new_product2, lly_new_product3, lly_new_product4, lly_new_product5, lly_new_product6;
    private TextView tv_new_product1_1, tv_new_product1_2, tv_new_product1_3, tv_new_product2_1, tv_new_product2_2, tv_new_product2_3,
            tv_new_product3_1, tv_new_product3_2, tv_new_product3_3, tv_new_product4_1, tv_new_product4_2, tv_new_product4_3, tv_new_product5_1,
            tv_new_product5_2, tv_new_product5_3, tv_new_product6_1, tv_new_product6_2, tv_new_product6_3;
    private ImageView img_new_product_ad;

    //热卖精选
    private LinearLayout lly_hot_product_big1, lly_hot_product_big2, lly_hot_product1, lly_hot_product2, lly_hot_product3, lly_hot_product4,
            lly_hot_product5, lly_hot_product6, lly_hot_product7, lly_hot_product8;
    private ImageView img_hot_product_big1, img_hot_product_big2, img_hot_product1, img_hot_product2, img_hot_product3,
            img_hot_product4, img_hot_product5, img_hot_product6, img_hot_product7, img_hot_product8;
    private TextView tv_hot_product_big1_1, tv_hot_product_big1_2, tv_hot_product_big2_1, tv_hot_product_big2_2, tv_hot_product1_1, tv_hot_product1_2,
            tv_hot_product1_3,tv_hot_product2_1, tv_hot_product2_2,tv_hot_product2_3, tv_hot_product3_1, tv_hot_product3_2,tv_hot_product3_3,
            tv_hot_product4_1, tv_hot_product4_2,tv_hot_product4_3, tv_hot_product5_1, tv_hot_product5_2,tv_hot_product5_3, tv_hot_product6_1,
            tv_hot_product6_2,tv_hot_product6_3, tv_hot_product7_1, tv_hot_product7_2,tv_hot_product7_3, tv_hot_product8_1, tv_hot_product8_2,
            tv_hot_product8_3;
    private ImageView img_hot_product_ad;

    //热门产品
    private LinearLayout lly_special_product1, lly_special_product2, lly_special_product3, lly_special_product4;
    private ImageView img_special_product1, img_special_product2, img_special_product3, img_special_product4;
    private TextView tv_special_product1_1, tv_special_product1_2, tv_special_product1_3, tv_special_product2_1, tv_special_product2_2,
            tv_special_product2_3, tv_special_product3_1, tv_special_product3_2, tv_special_product3_3, tv_special_product4_1,
            tv_special_product4_2, tv_special_product4_3;
    private TextView tv_special_product1_save, tv_special_product2_save, tv_special_product3_save, tv_special_product4_save;

    //全部商品
    private GridView all_product_gridview;
    private AllproductAdapter allproductAdapter;
    private int scrgetHight;
    private String url1, url2;//通用广告
    private String fanggeUrl1 = "", fanggeUrl2 = "", fanggeUrl3 = "", fanggeUrl4 = "", fanggeUrl5 = "", tonglanUrl1 = "www.baidu.com", tonglanUrl2 = "";//方格url，通栏url
    private String fanggeId1 = "", fanggeId2 = "", fanggeId3 = "", fanggeId4 = "", fanggeId5 = "";
    private String hot_Selected_id, hot_product_id, bargain_product_id, all_product_id;//热卖精选 热卖产品  特价产品 全部商品id

    private int page;

    List<HomepageDataResp.ResultEntity.DataEntity.ActivitiesEntity> list1;//特价产品
    List<HomepageDataResp.ResultEntity.DataEntity.ActivitiesEntity> list2;//热卖精选
    List<HomepageDataResp.ResultEntity.DataEntity.ActivitiesEntity> list3;//热卖产品


    @Nullable
    @Override
    public View onCreateView(LayoutInflater inflater, @Nullable ViewGroup container, @Nullable Bundle savedInstanceState) {
        if (rootView == null) {
            rootView = inflater.inflate(R.layout.homepage_fragment, container, false);
        }
        ViewGroup parent = (ViewGroup) rootView.getParent();
        if (parent != null) {
            parent.removeView(rootView);
        }

        return rootView;
    }

    @Override
    public void onActivityCreated(@Nullable Bundle savedInstanceState) {
        super.onActivityCreated(savedInstanceState);
        mActivity = getActivity();


        init();
//        initbanner();
        GetActivityType();

        ShareSDK.initSDK(mActivity, "1a9a901306a58");

    }

    private void init() {
        myApplication = MyApplication.getInstance();
        sharedPreferencesUtil = SharedPreferencesUtil.getInstance(mActivity);
        rly_classification = (RelativeLayout) mActivity.findViewById(R.id.rly_classification);
        rly_scan = (RelativeLayout) mActivity.findViewById(R.id.rly_scan);
        scan_img = (ImageView) mActivity.findViewById(R.id.scan_img);
        classification_img = (ImageView) mActivity.findViewById(R.id.classification_img);
        search_img = (ImageView) mActivity.findViewById(R.id.search_img);
        lly_et_search = (LinearLayout) mActivity.findViewById(R.id.lly_et_search);
        homepage_ptrScrollview = (PullToRefreshScrollView) rootView.findViewById(R.id.homepage_ptrlistview);

        lly_title_bar = (LinearLayout) rootView.findViewById(R.id.lly_title_bar);
        LoadBanner();
        homepage_ptrScrollview.setMode(PullToRefreshBase.Mode.BOTH);
        homepage_ptrScrollview.setOnRefreshListener2(new PullToRefreshBase.OnRefreshListener2<ScrollView>() {
            @Override
            public void onPullDownToRefresh(PullToRefreshBase<ScrollView> refreshView) {
                Log.e("ssss", "上拉刷新");
                LoadBanner();
//
            }

            @Override
            public void onPullUpToRefresh(PullToRefreshBase<ScrollView> refreshView) {
                GetAllProduct(MORE);
            }
        });

        //监听刷新上拉监听
        homepage_ptrScrollview.setOnScrollChangedListener1(new PullToRefreshScrollView.OnScrollChangedListener() {
            @Override
            public void onScrollChanged(PullToRefreshScrollView who, int l, int t, int oldl, int oldt) {

                if (banner != null && banner.getHeight() > 0) {
                    //define it for scroll height
                    int lHeight = banner.getHeight();
                    scrgetHight = t;
                    if (t < 100) {//=
//                        int progress = (int) (new Float(t) / new Float(lHeight) * 200);//255
//                        lly_title_bar.getBackground().setAlpha(progress);
                        lly_title_bar.setBackground(getResources().getDrawable(R.mipmap.rectangle2));
                        scan_img.setBackground(getResources().getDrawable(R.mipmap.scan_ddefault));
                        classification_img.setBackground(getResources().getDrawable(R.mipmap.classification_icon_default));
                        search_img.setBackground(getResources().getDrawable(R.mipmap.search_default));
                    } else {
//                        lly_title_bar.getBackground().setAlpha(255 - 55);
                        lly_title_bar.setBackground(getResources().getDrawable(R.mipmap.rectangle1));

                        scan_img.setBackground(getResources().getDrawable(scan));
                        classification_img.setBackground(getResources().getDrawable(R.mipmap.classification_icon));
                        search_img.setBackground(getResources().getDrawable(R.mipmap.search));

                    }
                }
            }
        });

        homepage_ptrScrollview.setOnScrollChangedListener2(new PullToRefreshScrollView.OnScrollChangedListener() {
            @Override
            public void onScrollChanged(PullToRefreshScrollView who, int l, int t, int oldl, int oldt) {
//                Log.e("ssss", "iiiii==>" + t);

                if (t < 0 && scrgetHight == 0) {
//                    lly_title_bar.setVisibility(View.GONE);
                } else {
                    lly_title_bar.setVisibility(View.VISIBLE);

                }
            }
        });

        //二维码扫描
        rly_scan.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View view) {
                Intent intent = new Intent();
                intent.setClass(mActivity, MipcaActivityCapture.class);
                intent.setFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP);
                startActivityForResult(intent, 1);
            }
        });

        //侧滑菜单
        rly_classification.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View view) {
//                mSlidingMenu.toggle();
                startActivity(new Intent(mActivity, SortSlidingActivity.class));
            }
        });

        //搜索
        lly_et_search.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View view) {
                startActivity(new Intent(mActivity, Search.class));
            }
        });

        homepage_productList = new ArrayList<HomepageDataResp.ResultEntity.DataEntity>();
        bannerList = new ArrayList<>();


        list1 = new ArrayList<HomepageDataResp.ResultEntity.DataEntity.ActivitiesEntity>();
        list2 = new ArrayList<HomepageDataResp.ResultEntity.DataEntity.ActivitiesEntity>();
        list3 = new ArrayList<HomepageDataResp.ResultEntity.DataEntity.ActivitiesEntity>();


    }

    private void initbanner() {
        homepage_ptrScrollview.getRefreshableView().removeView(hearderViewLayout);
        homepage_ptrScrollview.requestFocus();

        //homepager的页面
        hearderViewLayout = (ScrollView) LayoutInflater.from(mActivity).inflate(R.layout.homepage_banner, null);

        //Banner 适配器
        BannerPagerAdapter bannerPagerAdapter = new BannerAdapter(mActivity, bannerList);
        banner = (Banner) hearderViewLayout.findViewById(R.id.homepager_banner);
        banner.setDotGravity(Banner.CENTER).
                setDot(R.drawable.no_selected_dot, R.drawable.selected_dot).
                setAdapter(bannerPagerAdapter).
                setOnItemClickListener(new BannerPagerAdapter.onItemClickListener() {
                    @Override
                    public void onClick(int position) {
                        final BannerInfoResp.ResultEntity.DataEntity bannerInfo = bannerList.get(position);
                        if (!bannerInfo.getProduct_id().equals("0")) {
                            Log.e("ssss", "bannerInfo.getProduct_id()==>" + bannerInfo.getProduct_id());
                            Intent intent = new Intent(mActivity, ProductDetails.class);
                            intent.putExtra("id", bannerInfo.getProduct_id());
                            startActivity(intent);
                        } else if (!bannerInfo.getUrl().equals("")) {
                            Log.e("ssss", "bannerInfo.getUrl()==>" + bannerInfo.getUrl());
                            Intent intent = new Intent(mActivity, ActivityWebView.class);
                            intent.putExtra("url", bannerInfo.getUrl());
                            startActivity(intent);
                        }
                    }
                }).
                startAutoPlay();


        homepage_ptrScrollview.getRefreshableView().addView(hearderViewLayout);


        img_new_product_shelves_big = (ImageView) hearderViewLayout.findViewById(R.id.img_new_product_shelves_big);
        img_new_product1 = (ImageView) hearderViewLayout.findViewById(R.id.img_new_product1);
        img_new_product2 = (ImageView) hearderViewLayout.findViewById(R.id.img_new_product2);
        img_new_product3 = (ImageView) hearderViewLayout.findViewById(R.id.img_new_product3);
        img_new_product4 = (ImageView) hearderViewLayout.findViewById(R.id.img_new_product4);
        img_new_product5 = (ImageView) hearderViewLayout.findViewById(R.id.img_new_product5);
        img_new_product6 = (ImageView) hearderViewLayout.findViewById(R.id.img_new_product6);

        lly_new_product1 = (LinearLayout) hearderViewLayout.findViewById(R.id.lly_new_product1);
        lly_new_product2 = (LinearLayout) hearderViewLayout.findViewById(R.id.lly_new_product2);
        lly_new_product3 = (LinearLayout) hearderViewLayout.findViewById(R.id.lly_new_product3);
        lly_new_product4 = (LinearLayout) hearderViewLayout.findViewById(R.id.lly_new_product4);
        lly_new_product5 = (LinearLayout) hearderViewLayout.findViewById(R.id.lly_new_product5);
        lly_new_product6 = (LinearLayout) hearderViewLayout.findViewById(R.id.lly_new_product6);

        img_hot_product_big1 = (ImageView) hearderViewLayout.findViewById(R.id.img_hot_product_big1);
        img_hot_product_big2 = (ImageView) hearderViewLayout.findViewById(R.id.img_hot_product_big2);
        img_hot_product1 = (ImageView) hearderViewLayout.findViewById(R.id.img_hot_product1);
        img_hot_product2 = (ImageView) hearderViewLayout.findViewById(R.id.img_hot_product2);
        img_hot_product3 = (ImageView) hearderViewLayout.findViewById(R.id.img_hot_product3);
        img_hot_product4 = (ImageView) hearderViewLayout.findViewById(R.id.img_hot_product4);
        img_hot_product5 = (ImageView) hearderViewLayout.findViewById(R.id.img_hot_product5);
        img_hot_product6 = (ImageView) hearderViewLayout.findViewById(R.id.img_hot_product6);
        img_hot_product7 = (ImageView) hearderViewLayout.findViewById(R.id.img_hot_product7);
        img_hot_product8 = (ImageView) hearderViewLayout.findViewById(R.id.img_hot_product8);

        lly_hot_product_big1 = (LinearLayout) hearderViewLayout.findViewById(R.id.lly_hot_product_big1);
        lly_hot_product_big2 = (LinearLayout) hearderViewLayout.findViewById(R.id.lly_hot_product_big2);
        lly_hot_product1 = (LinearLayout) hearderViewLayout.findViewById(R.id.lly_hot_product1);
        lly_hot_product2 = (LinearLayout) hearderViewLayout.findViewById(R.id.lly_hot_product2);
        lly_hot_product3 = (LinearLayout) hearderViewLayout.findViewById(R.id.lly_hot_product3);
        lly_hot_product4 = (LinearLayout) hearderViewLayout.findViewById(R.id.lly_hot_product4);
        lly_hot_product5 = (LinearLayout) hearderViewLayout.findViewById(R.id.lly_hot_product5);
        lly_hot_product6 = (LinearLayout) hearderViewLayout.findViewById(R.id.lly_hot_product6);
        lly_hot_product7 = (LinearLayout) hearderViewLayout.findViewById(R.id.lly_hot_product7);
        lly_hot_product8 = (LinearLayout) hearderViewLayout.findViewById(R.id.lly_hot_product8);

        img_special_product1 = (ImageView) hearderViewLayout.findViewById(R.id.img_special_product1);
        img_special_product2 = (ImageView) hearderViewLayout.findViewById(R.id.img_special_product2);
        img_special_product3 = (ImageView) hearderViewLayout.findViewById(R.id.img_special_product3);
        img_special_product4 = (ImageView) hearderViewLayout.findViewById(R.id.img_special_product4);

        img_new_product_ad = (ImageView) hearderViewLayout.findViewById(R.id.img_new_product_ad);
        img_hot_product_ad = (ImageView) hearderViewLayout.findViewById(R.id.img_hot_product_ad);

        //新品上架
        tv_new_product1_1 = (TextView) hearderViewLayout.findViewById(R.id.tv_new_product1_1);
        tv_new_product1_2 = (TextView) hearderViewLayout.findViewById(R.id.tv_new_product1_2);
        tv_new_product1_3 = (TextView) hearderViewLayout.findViewById(R.id.tv_new_product1_3);
        tv_new_product2_1 = (TextView) hearderViewLayout.findViewById(R.id.tv_new_product2_1);
        tv_new_product2_2 = (TextView) hearderViewLayout.findViewById(R.id.tv_new_product2_2);
        tv_new_product2_3 = (TextView) hearderViewLayout.findViewById(R.id.tv_new_product2_3);
        tv_new_product3_1 = (TextView) hearderViewLayout.findViewById(R.id.tv_new_product3_1);
        tv_new_product3_2 = (TextView) hearderViewLayout.findViewById(R.id.tv_new_product3_2);
        tv_new_product3_3 = (TextView) hearderViewLayout.findViewById(R.id.tv_new_product3_3);
        tv_new_product4_1 = (TextView) hearderViewLayout.findViewById(R.id.tv_new_product4_1);
        tv_new_product4_2 = (TextView) hearderViewLayout.findViewById(R.id.tv_new_product4_2);
        tv_new_product4_3 = (TextView) hearderViewLayout.findViewById(R.id.tv_new_product4_3);
        tv_new_product5_1 = (TextView) hearderViewLayout.findViewById(R.id.tv_new_product5_1);
        tv_new_product5_2 = (TextView) hearderViewLayout.findViewById(R.id.tv_new_product5_2);
        tv_new_product5_3 = (TextView) hearderViewLayout.findViewById(R.id.tv_new_product5_3);
        tv_new_product6_1 = (TextView) hearderViewLayout.findViewById(R.id.tv_new_product6_1);
        tv_new_product6_2 = (TextView) hearderViewLayout.findViewById(R.id.tv_new_product6_2);
        tv_new_product6_3 = (TextView) hearderViewLayout.findViewById(R.id.tv_new_product6_3);

        tv_new_product1_3.getPaint().setFlags(Paint.STRIKE_THRU_TEXT_FLAG); //中划线
        tv_new_product2_3.getPaint().setFlags(Paint.STRIKE_THRU_TEXT_FLAG); //中划线
        tv_new_product3_3.getPaint().setFlags(Paint.STRIKE_THRU_TEXT_FLAG); //中划线
        tv_new_product4_3.getPaint().setFlags(Paint.STRIKE_THRU_TEXT_FLAG); //中划线
        tv_new_product5_3.getPaint().setFlags(Paint.STRIKE_THRU_TEXT_FLAG); //中划线
        tv_new_product6_3.getPaint().setFlags(Paint.STRIKE_THRU_TEXT_FLAG); //中划线

        tv_hot_product1_1 = (TextView) hearderViewLayout.findViewById(R.id.tv_hot_product1_1);
        tv_hot_product1_2 = (TextView) hearderViewLayout.findViewById(R.id.tv_hot_product1_2);
        tv_hot_product1_3= (TextView) hearderViewLayout.findViewById(R.id.tv_hot_product1_3);
        tv_hot_product2_1 = (TextView) hearderViewLayout.findViewById(R.id.tv_hot_product2_1);
        tv_hot_product2_2 = (TextView) hearderViewLayout.findViewById(R.id.tv_hot_product2_2);
        tv_hot_product2_3= (TextView) hearderViewLayout.findViewById(R.id.tv_hot_product2_3);
        tv_hot_product3_1 = (TextView) hearderViewLayout.findViewById(R.id.tv_hot_product3_1);
        tv_hot_product3_2 = (TextView) hearderViewLayout.findViewById(R.id.tv_hot_product3_2);
        tv_hot_product3_3= (TextView) hearderViewLayout.findViewById(R.id.tv_hot_product3_3);
        tv_hot_product4_1 = (TextView) hearderViewLayout.findViewById(R.id.tv_hot_product4_1);
        tv_hot_product4_2 = (TextView) hearderViewLayout.findViewById(R.id.tv_hot_product4_2);
        tv_hot_product4_3= (TextView) hearderViewLayout.findViewById(R.id.tv_hot_product4_3);
        tv_hot_product5_1 = (TextView) hearderViewLayout.findViewById(R.id.tv_hot_product5_1);
        tv_hot_product5_2 = (TextView) hearderViewLayout.findViewById(R.id.tv_hot_product5_2);
        tv_hot_product5_3= (TextView) hearderViewLayout.findViewById(R.id.tv_hot_product5_3);
        tv_hot_product6_1 = (TextView) hearderViewLayout.findViewById(R.id.tv_hot_product6_1);
        tv_hot_product6_2 = (TextView) hearderViewLayout.findViewById(R.id.tv_hot_product6_2);
        tv_hot_product6_3= (TextView) hearderViewLayout.findViewById(R.id.tv_hot_product6_3);
        tv_hot_product7_1 = (TextView) hearderViewLayout.findViewById(R.id.tv_hot_product7_1);
        tv_hot_product7_2 = (TextView) hearderViewLayout.findViewById(R.id.tv_hot_product7_2);
        tv_hot_product7_3= (TextView) hearderViewLayout.findViewById(R.id.tv_hot_product7_3);
        tv_hot_product8_1 = (TextView) hearderViewLayout.findViewById(R.id.tv_hot_product8_1);
        tv_hot_product8_2 = (TextView) hearderViewLayout.findViewById(R.id.tv_hot_product8_2);
        tv_hot_product8_3= (TextView) hearderViewLayout.findViewById(R.id.tv_hot_product8_3);

        tv_hot_product1_3.getPaint().setFlags(Paint.STRIKE_THRU_TEXT_FLAG); //中划线
        tv_hot_product2_3.getPaint().setFlags(Paint.STRIKE_THRU_TEXT_FLAG); //中划线
        tv_hot_product3_3.getPaint().setFlags(Paint.STRIKE_THRU_TEXT_FLAG); //中划线
        tv_hot_product4_3.getPaint().setFlags(Paint.STRIKE_THRU_TEXT_FLAG); //中划线
        tv_hot_product5_3.getPaint().setFlags(Paint.STRIKE_THRU_TEXT_FLAG); //中划线
        tv_hot_product6_3.getPaint().setFlags(Paint.STRIKE_THRU_TEXT_FLAG); //中划线
        tv_hot_product7_3.getPaint().setFlags(Paint.STRIKE_THRU_TEXT_FLAG); //中划线
        tv_hot_product8_3.getPaint().setFlags(Paint.STRIKE_THRU_TEXT_FLAG); //中划线

        //特价产品
//        tv_special_product1_save = (TextView) hearderViewLayout.findViewById(R.id.tv_special_product1_save);
//        tv_special_product2_save = (TextView) hearderViewLayout.findViewById(R.id.tv_special_product2_save);
//        tv_special_product3_save = (TextView) hearderViewLayout.findViewById(R.id.tv_special_product3_save);
//        tv_special_product4_save = (TextView) hearderViewLayout.findViewById(R.id.tv_special_product4_save);
        tv_special_product1_1 = (TextView) hearderViewLayout.findViewById(R.id.tv_special_product1_1);
        tv_special_product1_2 = (TextView) hearderViewLayout.findViewById(R.id.tv_special_product1_2);
        tv_special_product1_3 = (TextView) hearderViewLayout.findViewById(R.id.tv_special_product1_3);
        tv_special_product2_1 = (TextView) hearderViewLayout.findViewById(R.id.tv_special_product2_1);
        tv_special_product2_2 = (TextView) hearderViewLayout.findViewById(R.id.tv_special_product2_2);
        tv_special_product2_3 = (TextView) hearderViewLayout.findViewById(R.id.tv_special_product2_3);
        tv_special_product3_1 = (TextView) hearderViewLayout.findViewById(R.id.tv_special_product3_1);
        tv_special_product3_2 = (TextView) hearderViewLayout.findViewById(R.id.tv_special_product3_2);
        tv_special_product3_3 = (TextView) hearderViewLayout.findViewById(R.id.tv_special_product3_3);
        tv_special_product4_1 = (TextView) hearderViewLayout.findViewById(R.id.tv_special_product4_1);
        tv_special_product4_2 = (TextView) hearderViewLayout.findViewById(R.id.tv_special_product4_2);
        tv_special_product4_3 = (TextView) hearderViewLayout.findViewById(R.id.tv_special_product4_3);

        lly_special_product1 = (LinearLayout) hearderViewLayout.findViewById(R.id.lly_special_product1);
        lly_special_product2 = (LinearLayout) hearderViewLayout.findViewById(R.id.lly_special_product2);
        lly_special_product3 = (LinearLayout) hearderViewLayout.findViewById(R.id.lly_special_product3);
        lly_special_product4 = (LinearLayout) hearderViewLayout.findViewById(R.id.lly_special_product4);

        tv_special_product1_3.getPaint().setFlags(Paint.STRIKE_THRU_TEXT_FLAG); //中划线
        tv_special_product2_3.getPaint().setFlags(Paint.STRIKE_THRU_TEXT_FLAG); //中划线
        tv_special_product3_3.getPaint().setFlags(Paint.STRIKE_THRU_TEXT_FLAG); //中划线
        tv_special_product4_3.getPaint().setFlags(Paint.STRIKE_THRU_TEXT_FLAG); //中划线

        //全部商品
        all_productList = new ArrayList<>();
        all_product_gridview = (GridView) mActivity.findViewById(R.id.all_product_gridview);
        allproductAdapter = new AllproductAdapter(all_productList);
        all_product_gridview.setAdapter(allproductAdapter);

        GetHomepageData();


        initFour_Button();//四个布局（伴手礼，喵星人，汪星人，海外购）
        initTop_Five_Product();//新品上架上面的5个活动产品
        initProductRelativeLayout();//新品上架,热卖产品，特价产品，积分产品

        img_new_product_shelves_big.setOnClickListener(this);
        lly_new_product1.setOnClickListener(this);
        lly_new_product2.setOnClickListener(this);
        lly_new_product3.setOnClickListener(this);
        lly_new_product4.setOnClickListener(this);
        lly_new_product5.setOnClickListener(this);
        lly_new_product6.setOnClickListener(this);
        img_new_product_ad.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                Intent intent = new Intent(mActivity, ActivityWebView.class);
                intent.putExtra("url", tonglanUrl1);
                startActivity(intent);
            }
        });
        img_hot_product_ad.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                Intent intent = new Intent(mActivity, ActivityWebView.class);
                Log.e("url", "tonglanUrl2==" + tonglanUrl2);
                intent.putExtra("url", tonglanUrl2);
                startActivity(intent);
            }
        });
        lly_hot_product_big1.setOnClickListener(this);
        lly_hot_product_big2.setOnClickListener(this);
        lly_hot_product1.setOnClickListener(this);
        lly_hot_product2.setOnClickListener(this);
        lly_hot_product3.setOnClickListener(this);
        lly_hot_product4.setOnClickListener(this);
        lly_hot_product5.setOnClickListener(this);
        lly_hot_product6.setOnClickListener(this);
        lly_hot_product7.setOnClickListener(this);
        lly_hot_product8.setOnClickListener(this);

        lly_special_product1.setOnClickListener(this);
        lly_special_product2.setOnClickListener(this);
        lly_special_product3.setOnClickListener(this);
        lly_special_product4.setOnClickListener(this);


    }


    @Override
    public void onClick(View view) {
        Intent intent = new Intent(mActivity, ProductDetails.class);

        switch (view.getId()) {

            //特价产品
            case R.id.img_new_product_shelves_big:
                if (list1.size() > 0) {
                    intent.putExtra("id", list1.get(0).getId());
                    startActivity(intent);
                } else {
                    CommonUtil.showToast(mActivity, "暂无商品");
                    return;
                }

                break;
            case R.id.lly_new_product1:
                if (list1.size() > 1) {
                    intent.putExtra("id", list1.get(1).getId());
                    startActivity(intent);
                } else {
                    CommonUtil.showToast(mActivity, "暂无商品");
                    return;
                }

                break;
            case R.id.lly_new_product2:
                if (list1.size() > 2) {
                    intent.putExtra("id", list1.get(2).getId());
                    startActivity(intent);

                } else {
                    CommonUtil.showToast(mActivity, "暂无商品");
                    return;
                }

                break;
            case R.id.lly_new_product3:
                if (list1.size() > 3) {
                    intent.putExtra("id", list1.get(3).getId());
                    startActivity(intent);
                } else {
                    CommonUtil.showToast(mActivity, "暂无商品");
                    return;
                }

                break;
            case R.id.lly_new_product4:
                if (list1.size() > 4) {
                    intent.putExtra("id", list1.get(4).getId());
                    startActivity(intent);
                } else {
                    CommonUtil.showToast(mActivity, "暂无商品");
                    return;
                }

                break;
            case R.id.lly_new_product5:
                if (list1.size() > 5) {
                    intent.putExtra("id", list1.get(5).getId());
                    startActivity(intent);
                } else {
                    CommonUtil.showToast(mActivity, "暂无商品");
                    return;
                }

                break;
            case R.id.lly_new_product6:
                if (list1.size() > 6) {
                    intent.putExtra("id", list1.get(6).getId());
                    startActivity(intent);
                } else {
                    CommonUtil.showToast(mActivity, "暂无商品");
                    return;
                }

                break;


            //热卖精选
            case R.id.lly_hot_product_big1:
                if (list2.size() > 0) {
                    intent.putExtra("id", list2.get(0).getId());
                    startActivity(intent);
                } else {
                    CommonUtil.showToast(mActivity, "暂无商品");
                    return;
                }

                break;
            case R.id.lly_hot_product_big2:
                if (list2.size() > 1) {
                    intent.putExtra("id", list2.get(1).getId());
                    startActivity(intent);
                } else {
                    CommonUtil.showToast(mActivity, "暂无商品");
                    return;
                }

                break;
            case R.id.lly_hot_product1:
                if (list2.size() > 2) {
                    intent.putExtra("id", list2.get(2).getId());
                    startActivity(intent);
                } else {
                    CommonUtil.showToast(mActivity, "暂无商品");
                    return;
                }

                break;
            case R.id.lly_hot_product2:
                if (list2.size() > 3) {
                    intent.putExtra("id", list2.get(3).getId());
                    startActivity(intent);
                } else {
                    CommonUtil.showToast(mActivity, "暂无商品");
                    return;
                }

                break;
            case R.id.lly_hot_product3:
                if (list2.size() > 4) {
                    intent.putExtra("id", list2.get(4).getId());
                    startActivity(intent);
                } else {
                    CommonUtil.showToast(mActivity, "暂无商品");
                    return;
                }

                break;
            case R.id.lly_hot_product4:
                if (list2.size() > 5) {
                    intent.putExtra("id", list2.get(5).getId());
                    startActivity(intent);
                } else {
                    CommonUtil.showToast(mActivity, "暂无商品");
                    return;
                }

                break;
            case R.id.lly_hot_product5:
                if (list2.size() > 6) {
                    intent.putExtra("id", list2.get(6).getId());
                    startActivity(intent);
                } else {
                    CommonUtil.showToast(mActivity, "暂无商品");
                    return;
                }

                break;
            case R.id.lly_hot_product6:
                if (list2.size() > 7) {
                    intent.putExtra("id", list2.get(7).getId());
                    startActivity(intent);
                } else {
                    CommonUtil.showToast(mActivity, "暂无商品");
                    return;
                }

                break;
            case R.id.lly_hot_product7:
                if (list2.size() > 8) {
                    intent.putExtra("id", list2.get(8).getId());
                    startActivity(intent);
                } else {
                    CommonUtil.showToast(mActivity, "暂无商品");
                    return;
                }

                break;
            case R.id.lly_hot_product8:
                if (list2.size() > 9) {
                    intent.putExtra("id", list2.get(9).getId());
                    startActivity(intent);
                } else {
                    CommonUtil.showToast(mActivity, "暂无商品");
                    return;
                }

                break;


            //热卖产品
            case R.id.lly_special_product1:
                if (list3.size() > 0) {
                    intent.putExtra("id", list3.get(0).getId());
                    startActivity(intent);
                } else {
                    CommonUtil.showToast(mActivity, "暂无商品");
                    return;
                }

                break;
            case R.id.lly_special_product2:
                if (list3.size() > 1) {
                    intent.putExtra("id", list3.get(1).getId());
                    startActivity(intent);
                } else {
                    CommonUtil.showToast(mActivity, "暂无商品");
                    return;
                }

                break;
            case R.id.lly_special_product3:
                if (list3.size() > 2) {
                    intent.putExtra("id", list3.get(2).getId());
                    startActivity(intent);
                } else {
                    CommonUtil.showToast(mActivity, "暂无商品");
                    return;
                }

                break;
            case R.id.lly_special_product4:
                if (list3.size() > 3) {
                    intent.putExtra("id", list3.get(3).getId());
                    startActivity(intent);
                } else {
                    CommonUtil.showToast(mActivity, "暂无商品");
                    return;
                }

                break;


        }
    }

    //获取  (全部商品)
    private void GetAllProduct(final int type) {
        AllProductReq req = new AllProductReq();
        if (type == LOAD || type == REFRESH) {
            page = 1;
        } else {
            page = (all_productList.size() / 10 + 1);
        }
        req.setType("0");
        req.setPage(page + "");
        req.setPage_size("10");
        req.setSort("id");
        req.setOrder("asc");


        RequestParams params = new RequestParams();
        params.put("secret", req.getSecret());

        Async_http_get.get(Const.COMMON_ADDRESS + req.urlString(), params, new JsonHttpResponseHandler() {
            @Override
            public void onSuccess(int statusCode, Header[] headers, JSONObject response) {
                super.onSuccess(statusCode, headers, response);
                CustomProgressDialog.Dismiss();
                homepage_ptrScrollview.onRefreshComplete();
                Log.e("ssss", "获取全部商品");
//                Log.e("ssss", "GetAllProductjson1111==" + response);
                String errno = response.optString("errno");
                String errmsg = response.optString("errmsg");
                if (errno.equals("000")) {
                    AllProductResp resp = GsonImpl.get().toObject(response.toString(), AllProductResp.class);

                    if (type == LOAD || type == REFRESH) {
                        all_productList.clear();
                        all_productList.addAll(resp.getResult().getData());
                    } else {
                        all_productList.addAll(resp.getResult().getData());
                    }
                    if (all_productList.size() % 10 > 0) {
                        homepage_ptrScrollview.setMode(PullToRefreshBase.Mode.PULL_FROM_START);
                    } else {
                        homepage_ptrScrollview.setMode(PullToRefreshBase.Mode.BOTH);
                    }
                    allproductAdapter.notifyDataSetChanged();

                } else {
                }
            }

            @Override
            public void onFailure(int statusCode, Header[] headers, String responseString, Throwable throwable) {
                super.onFailure(statusCode, headers, responseString, throwable);
                CommonUtil.showToast(mActivity, "网络连接失败");
                homepage_ptrScrollview.onRefreshComplete();
            }
        });
    }

    //获取数据
    private void GetHomepageData() {
//        CustomProgressDialog.createDialog(mActivity).show();
        HomepageDataReq req = new HomepageDataReq();
        req.setTime(System.currentTimeMillis() + "");

        RequestParams params = new RequestParams();
        params.put("secret", req.getSecret());
        Async_http_get.get(Const.COMMON_ADDRESS + req.urlString(), params, new JsonHttpResponseHandler() {
                    @Override
                    public void onSuccess(int statusCode, Header[] headers, JSONObject response) {
                        super.onSuccess(statusCode, headers, response);
//                Log.e("url", "HomepageData_json==" + response);
//                CustomProgressDialog.Dismiss();
                        Log.e("ssss", "获取首页的数据");
                        String errno = response.optString("errno");
                        String errmsg = response.optString("errmsg");
                        if (errno.equals("000")) {
                            HomepageDataResp resp = GsonImpl.get().toObject(response.toString(), HomepageDataResp.class);
                            homepage_productList.clear();
                            homepage_productList.addAll(resp.getResult().getData());


                            for (int i = 0; i < homepage_productList.size(); i++) {
                                if (homepage_productList.get(i).getName().equals("特价产品")) {
                                    list1.clear();
                                    list1.addAll(homepage_productList.get(0).getActivities());

                                    Log.e("ssss", "特价产品数量" + list1.size() + "");
                                    //特价产品
                                    if (list1.size() > 0) {
                                        ImageLoader.getInstance().displayImage(list1.get(0).getThumb().get(0).toString(), img_new_product_shelves_big, displayImageOptions_tejia);

                                    }
                                    if (list1.size() > 1) {
                                        ImageLoader.getInstance().displayImage(list1.get(1).getList_thumb(), img_new_product1, displayImageOptions);
                                        tv_new_product1_1.setText(list1.get(1).getList_title());
                                        tv_new_product1_2.setText(list1.get(1).getPrice() + "元");
                                        tv_new_product1_3.setText(list1.get(1).getMarket_price() + "元");
                                    }
                                    if (list1.size() > 2) {
                                        ImageLoader.getInstance().displayImage(list1.get(2).getList_thumb(), img_new_product2, displayImageOptions);
                                        tv_new_product2_1.setText(list1.get(2).getList_title());
                                        tv_new_product2_2.setText(list1.get(2).getPrice() + "元");
                                        tv_new_product2_3.setText(list1.get(2).getMarket_price() + "元");
                                    }
                                    if (list1.size() > 3) {
                                        ImageLoader.getInstance().displayImage(list1.get(3).getList_thumb(), img_new_product3, displayImageOptions);
                                        tv_new_product3_1.setText(list1.get(3).getList_title());
                                        tv_new_product3_2.setText(list1.get(3).getPrice() + "元");
                                        tv_new_product3_3.setText(list1.get(3).getMarket_price() + "元");
                                    }
                                    if (list1.size() > 4) {
                                        ImageLoader.getInstance().displayImage(list1.get(4).getList_thumb(), img_new_product4, displayImageOptions);
                                        tv_new_product4_1.setText(list1.get(4).getList_title());
                                        tv_new_product4_2.setText(list1.get(4).getPrice() + "元");
                                        tv_new_product4_3.setText(list1.get(4).getMarket_price() + "元");
                                    }
                                    if (list1.size() > 5) {
                                        ImageLoader.getInstance().displayImage(list1.get(5).getList_thumb(), img_new_product5, displayImageOptions);
                                        tv_new_product5_1.setText(list1.get(5).getList_title());
                                        tv_new_product5_2.setText(list1.get(5).getPrice() + "元");
                                        tv_new_product5_3.setText(list1.get(5).getMarket_price() + "元");
                                    }
                                    if (list1.size() > 6) {
                                        ImageLoader.getInstance().displayImage(list1.get(6).getList_thumb(), img_new_product6, displayImageOptions);
                                        tv_new_product6_1.setText(list1.get(6).getList_title());
                                        tv_new_product6_2.setText(list1.get(6).getPrice() + "元");
                                        tv_new_product6_3.setText(list1.get(6).getMarket_price() + "元");
                                    }


                                }
                                if (homepage_productList.get(i).getName().equals("热卖精选")) {
                                    list2.clear();
                                    list2.addAll(homepage_productList.get(1).getActivities());
                                    if (list2.size() > 0) {
                                        ImageLoader.getInstance().displayImage(list2.get(0).getList_thumb(), img_hot_product_big1, displayImageOptions);
                                    }
                                    if (list2.size() > 1) {
                                        ImageLoader.getInstance().displayImage(list2.get(1).getList_thumb(), img_hot_product_big2, displayImageOptions);
                                    }
                                    if (list2.size() > 2) {
                                        ImageLoader.getInstance().displayImage(list2.get(2).getList_thumb(), img_hot_product1, displayImageOptions);
                                        tv_hot_product1_1.setText(list2.get(2).getList_title());
                                        tv_hot_product1_2.setText(list2.get(2).getPrice());
                                        tv_hot_product1_3.setText(list2.get(2).getMarket_price());
                                    }
                                    if (list2.size() > 3) {
                                        ImageLoader.getInstance().displayImage(list2.get(3).getList_thumb(), img_hot_product2, displayImageOptions);
                                        tv_hot_product2_1.setText(list2.get(3).getList_title());
                                        tv_hot_product2_2.setText(list2.get(3).getPrice());
                                        tv_hot_product2_3.setText(list2.get(3).getMarket_price());
                                    }
                                    if (list2.size() > 4) {
                                        ImageLoader.getInstance().displayImage(list2.get(4).getList_thumb(), img_hot_product3, displayImageOptions);
                                        tv_hot_product3_1.setText(list2.get(4).getList_title());
                                        tv_hot_product3_2.setText(list2.get(4).getPrice());
                                        tv_hot_product3_3.setText(list2.get(4).getMarket_price());
                                    }
                                    if (list2.size() > 5) {
                                        ImageLoader.getInstance().displayImage(list2.get(5).getList_thumb(), img_hot_product4, displayImageOptions);
                                        tv_hot_product4_1.setText(list2.get(5).getList_title());
                                        tv_hot_product4_2.setText(list2.get(5).getPrice());
                                        tv_hot_product4_3.setText(list2.get(5).getMarket_price());
                                    }
                                    if (list2.size() > 6) {
                                        ImageLoader.getInstance().displayImage(list2.get(6).getList_thumb(), img_hot_product5, displayImageOptions);
                                        tv_hot_product5_1.setText(list2.get(6).getList_title());
                                        tv_hot_product5_2.setText(list2.get(6).getPrice());
                                        tv_hot_product5_3.setText(list2.get(6).getMarket_price());
                                    }
                                    if (list2.size() > 7) {
                                        ImageLoader.getInstance().displayImage(list2.get(7).getList_thumb(), img_hot_product6, displayImageOptions);
                                        tv_hot_product6_1.setText(list2.get(7).getList_title());
                                        tv_hot_product6_2.setText(list2.get(7).getPrice());
                                        tv_hot_product6_3.setText(list2.get(7).getMarket_price());
                                    }
                                    if (list2.size() > 8) {
                                        ImageLoader.getInstance().displayImage(list2.get(8).getList_thumb(), img_hot_product7, displayImageOptions);
                                        tv_hot_product7_1.setText(list2.get(8).getList_title());
                                        tv_hot_product7_2.setText(list2.get(8).getPrice());
                                        tv_hot_product7_3.setText(list2.get(8).getMarket_price());
                                    }
                                    if (list2.size() > 9) {
                                        ImageLoader.getInstance().displayImage(list2.get(9).getList_thumb(), img_hot_product8, displayImageOptions);

                                        tv_hot_product8_1.setText(list2.get(9).getList_title());
                                        tv_hot_product8_2.setText(list2.get(9).getPrice());
                                        tv_hot_product8_3.setText(list2.get(9).getMarket_price());
                                    }

                                }
                                if (homepage_productList.get(i).getName().equals("热卖产品")) {
                                    list3.clear();
                                    list3.addAll(homepage_productList.get(2).getActivities());

                                    if (list3.size() > 0) {
                                        ImageLoader.getInstance().displayImage(list3.get(0).getList_thumb(), img_special_product1, displayImageOptions);
                                        tv_special_product1_1.setText(list3.get(0).getList_title());
                                        tv_special_product1_2.setText(list3.get(0).getPrice());
                                        tv_special_product1_3.setText(list3.get(0).getMarket_price());
                                    }
                                    if (list3.size() > 1) {
                                        ImageLoader.getInstance().displayImage(list3.get(1).getList_thumb(), img_special_product2, displayImageOptions);
                                        tv_special_product2_1.setText(list3.get(1).getList_title());
                                        tv_special_product2_2.setText(list3.get(1).getPrice());
                                        tv_special_product2_3.setText(list3.get(1).getMarket_price());
                                    }
                                    if (list3.size() > 2) {
                                        ImageLoader.getInstance().displayImage(list3.get(2).getList_thumb(), img_special_product3, displayImageOptions);
                                        tv_special_product3_1.setText(list3.get(2).getList_title());
                                        tv_special_product3_2.setText(list3.get(2).getPrice());
                                        tv_special_product3_3.setText(list3.get(2).getMarket_price());
                                    }
                                    if (list3.size() > 3) {
                                        ImageLoader.getInstance().displayImage(list3.get(3).getList_thumb(), img_special_product4, displayImageOptions);
                                        tv_special_product4_1.setText(list3.get(3).getList_title());
                                        tv_special_product4_2.setText(list3.get(3).getPrice());
                                        tv_special_product4_3.setText(list3.get(3).getMarket_price());
                                    }
                                }
                            }

//
//                    if (tv_new_product1_2.getText().toString().equals(tv_new_product1_3.getText().toString())) {
//                        tv_new_product1_3.setVisibility(View.GONE);
//                    }
//                    if (tv_new_product2_2.getText().toString().equals(tv_new_product2_3.getText().toString())) {
//                        tv_new_product2_3.setVisibility(View.GONE);
//                    }
//                    if (tv_new_product3_2.getText().toString().equals(tv_new_product3_3.getText().toString())) {
//                        tv_new_product3_3.setVisibility(View.GONE);
//                    }
//                    if (tv_new_product4_2.getText().toString().equals(tv_new_product4_3.getText().toString())) {
//                        tv_new_product4_3.setVisibility(View.GONE);
//                    }
//                    if (tv_new_product5_2.getText().toString().equals(tv_new_product5_3.getText().toString())) {
//                        tv_new_product5_3.setVisibility(View.GONE);
//                    }
//                    if (tv_new_product6_2.getText().toString().equals(tv_new_product6_3.getText().toString())) {
//                        tv_new_product6_3.setVisibility(View.GONE);
//                    }
//
//                    if (resp.getResult().getData().get(0).getActivities().get(1).getPrice() == null) {
//                        tv_new_product1_1.setVisibility(View.INVISIBLE);
//                        tv_new_product1_2.setVisibility(View.INVISIBLE);
//                        tv_new_product1_3.setVisibility(View.INVISIBLE);
//                    }

//                    if (resp.getResult().getData().get(0).getActivities().get(2).getPrice() == null) {
//                        tv_new_product2_1.setVisibility(View.INVISIBLE);
//                        tv_new_product2_2.setVisibility(View.INVISIBLE);
//                        tv_new_product2_3.setVisibility(View.INVISIBLE);
//                    }
//                    if (resp.getResult().getData().get(0).getActivities().get(3).getPrice() == null) {
//                        tv_new_product3_1.setVisibility(View.INVISIBLE);
//                        tv_new_product3_2.setVisibility(View.INVISIBLE);
//                        tv_new_product3_3.setVisibility(View.INVISIBLE);
//                    }
//                    if (resp.getResult().getData().get(0).getActivities().get(4).getPrice() == null) {
//                        tv_new_product4_1.setVisibility(View.INVISIBLE);
//                        tv_new_product4_2.setVisibility(View.INVISIBLE);
//                        tv_new_product4_3.setVisibility(View.INVISIBLE);
//                    }
//                    if (resp.getResult().getData().get(0).getActivities().get(5).getPrice() == null) {
//                        tv_new_product5_1.setVisibility(View.INVISIBLE);
//                        tv_new_product5_2.setVisibility(View.INVISIBLE);
//                        tv_new_product5_3.setVisibility(View.INVISIBLE);
//                    }
//                    if (resp.getResult().getData().get(0).getActivities().get(6).getPrice() == null) {
//                        tv_new_product6_1.setVisibility(View.INVISIBLE);
//                        tv_new_product6_2.setVisibility(View.INVISIBLE);
//                        tv_new_product6_3.setVisibility(View.INVISIBLE);
//                    }


                            //热卖产品


//                    double price1 = 0, price2 = 0, price3 = 0, price4 = 0;
//                    if (resp.getResult().getData().get(2).getActivities().get(0).getMarket_price().equals("") || resp.getResult().getData().get(2).getActivities().get(0).getPrice().equals("")) {
//                        price1 = 0;
//                    } else {
//                        price1 = Double.parseDouble(resp.getResult().getData().get(2).getActivities().get(0).getMarket_price()) - Double.parseDouble(resp.getResult().getData().get(2).getActivities().get(0).getPrice());
//                    }
//
//                    if (resp.getResult().getData().get(2).getActivities().get(1).getId() == 0) {
//                        price2 = 0;
//                    } else {
//                        price2 = Double.parseDouble(resp.getResult().getData().get(2).getActivities().get(1).getMarket_price()) - Double.parseDouble(resp.getResult().getData().get(2).getActivities().get(1).getPrice());
//                    }
//
//                    if (resp.getResult().getData().get(2).getActivities().get(2).getId() == 0) {
//                        price3 = 0;
//                    } else {
//                        price3 = Double.parseDouble(resp.getResult().getData().get(2).getActivities().get(2).getMarket_price()) - Double.parseDouble(resp.getResult().getData().get(2).getActivities().get(2).getPrice());
//                    }
//
//                    if (resp.getResult().getData().get(2).getActivities().get(3).getId() == 0) {
//                        price4 = 0;
//                    } else {
//                        price4 = Double.parseDouble(resp.getResult().getData().get(2).getActivities().get(3).getMarket_price()) - Double.parseDouble(resp.getResult().getData().get(2).getActivities().get(3).getPrice());
//                    }
//                    tv_special_product1_save.setText("省" + price1 + "");
//                    tv_special_product2_save.setText("省" + price2 + "");
//                    tv_special_product3_save.setText("省" + price3 + "");
//                    tv_special_product4_save.setText("省" + price4 + "");

                        } else {
                            CommonUtil.showToast(mActivity, errmsg);
                        }
                        GetAllProduct(REFRESH);
                        LoadNoticeAD();

                    }

                    @Override
                    public void onFailure(int statusCode, Header[] headers, String
                            responseString, Throwable throwable) {
                        super.onFailure(statusCode, headers, responseString, throwable);
                    }
                }

        );
    }

    //四个按钮（通宝，推荐，推广，分类）

    private void initFour_Button() {
        lly_hand_gift = (LinearLayout) hearderViewLayout.findViewById(R.id.lly_hand_gift);
        lly_cat = (LinearLayout) hearderViewLayout.findViewById(R.id.lly_cat);
        lly_dog = (LinearLayout) hearderViewLayout.findViewById(R.id.lly_dog);
        lly_overseas_buy = (LinearLayout) hearderViewLayout.findViewById(R.id.lly_overseas_buy);
        lly_hand_gift.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
//                Intent intent = new Intent(mActivity, HandGift.class);
//                intent.putExtra("id", 3);
//                intent.putExtra("title", "伴手礼");
//                startActivity(intent);
                if (myApplication.getDataEntity() == null) {
                    startActivity(new Intent(mActivity, LoginActivity.class));

                } else {
                    startActivity(new Intent(mActivity, MyTbActivity.class));
                }
            }
        });

        lly_cat.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
//                Intent intent = new Intent(mActivity, HandGift.class);
//                intent.putExtra("id", 4);
//                intent.putExtra("title", "喵星人");
//                startActivity(intent);
                if (myApplication.getDataEntity() == null) {
                    startActivity(new Intent(mActivity, LoginActivity.class));

                } else {
                    startActivity(new Intent(mActivity, RecommendActivity.class));

                }

            }
        });
        lly_dog.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                Intent intent = new Intent(mActivity, MipcaActivityCapture.class);
//                intent.putExtra("id", 5);
//                intent.putExtra("title", "汪星人");
                startActivity(intent);
            }
        });
        lly_overseas_buy.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                startActivity(new Intent(mActivity, SortSlidingActivity.class));
            }
        });
    }

    //新品上架的上的5个活动产品的点击事件
    private void initTop_Five_Product() {
        img_top_product1 = (ImageView) mActivity.findViewById(R.id.img_top_product1);
        img_top_product2 = (ImageView) mActivity.findViewById(R.id.img_top_product2);
        img_top_product3 = (ImageView) mActivity.findViewById(R.id.img_top_product3);
        img_top_product4 = (ImageView) mActivity.findViewById(R.id.img_top_product4);
        img_top_product5 = (ImageView) mActivity.findViewById(R.id.img_top_product5);
        img_top_product1.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(android.view.View v) {
                if (!fanggeUrl1.equals("")) {
                    Intent intent = new Intent(mActivity, ActivityWebView.class);
                    intent.putExtra("url", fanggeUrl1);
                    startActivity(intent);
                } else if (!fanggeId1.equals("")) {
                    Intent intent = new Intent(mActivity, ProductDetails.class);
                    intent.putExtra("id", Integer.parseInt(fanggeId1));
                    startActivity(intent);
                }
            }
        });
        img_top_product2.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(android.view.View v) {
                if (!fanggeUrl2.equals("")) {
                    Intent intent = new Intent(mActivity, ActivityWebView.class);
                    intent.putExtra("url", fanggeUrl2);
                    startActivity(intent);
                } else if (!fanggeId2.equals("")) {
                    Intent intent = new Intent(mActivity, ProductDetails.class);
                    intent.putExtra("id", Integer.parseInt(fanggeId2));
                    startActivity(intent);
                }
            }
        });
        img_top_product3.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(android.view.View v) {
                if (!fanggeUrl3.equals("")) {
                    Intent intent = new Intent(mActivity, ActivityWebView.class);
                    intent.putExtra("url", fanggeUrl3);
                    startActivity(intent);
                } else if (!fanggeId3.equals("")) {
                    Intent intent = new Intent(mActivity, ProductDetails.class);
                    intent.putExtra("id", Integer.parseInt(fanggeId3));
                    startActivity(intent);
                }
            }
        });
        img_top_product4.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(android.view.View v) {
                if (!fanggeUrl4.equals("")) {
                    Intent intent = new Intent(mActivity, ActivityWebView.class);
                    intent.putExtra("url", fanggeUrl4);
                    startActivity(intent);
                } else if (!fanggeId4.equals("")) {
                    Intent intent = new Intent(mActivity, ProductDetails.class);
                    intent.putExtra("id", Integer.parseInt(fanggeId4));
                    startActivity(intent);
                }
            }
        });

        img_top_product5.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(android.view.View v) {
                if (!fanggeUrl5.equals("")) {
                    Intent intent = new Intent(mActivity, ActivityWebView.class);
                    intent.putExtra("url", fanggeUrl5);
                    startActivity(intent);
                } else if (!fanggeId5.equals("")) {
                    Intent intent = new Intent(mActivity, ProductDetails.class);
                    intent.putExtra("id", Integer.parseInt(fanggeId5));
                    startActivity(intent);
                }
            }
        });
    }

    //新品上架，热门产品，特价产品，积分产品的“更多”的点击事件
    private void initProductRelativeLayout() {
        rly_new_product_shelves = (RelativeLayout) mActivity.findViewById(R.id.rly_new_product_shelves);
        rly_hot_product = (RelativeLayout) mActivity.findViewById(R.id.rly_hot_product);
        rly_special_product = (RelativeLayout) mActivity.findViewById(R.id.rly_special_product);
        rly_integral_product = (RelativeLayout) mActivity.findViewById(R.id.rly_integral_product);

        //特价产品
        rly_new_product_shelves.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                Intent intent = new Intent(mActivity, SpecialProduct.class);
                intent.putExtra("id", bargain_product_id);
                startActivity(intent);

            }
        });

        //热卖精选
        rly_hot_product.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                Intent intent = new Intent(mActivity, NewProductShelves.class);
                intent.putExtra("id", hot_Selected_id);
                startActivity(intent);
            }
        });

        //热卖产品
        rly_special_product.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                Intent intent = new Intent(mActivity, HotProduct.class);
                intent.putExtra("id", hot_product_id);
                startActivity(intent);
            }
        });

        //全部商品
        rly_integral_product.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                Intent intent = new Intent(mActivity, AllProduct.class);
                intent.putExtra("id", all_product_id);
                intent.putExtra("titlename", "全部商品");
                startActivity(intent);
            }
        });
    }


    @Override
    public void onActivityResult(int requestCode, int resultCode, Intent data) {
        super.onActivityResult(requestCode, resultCode, data);
        switch (requestCode) {
            case 1:
                if (resultCode == RESULT_OK) {
                    Bundle bundle = data.getExtras();
                    //显示扫描到的内容

                    Log.e("ssss", "二维码URL==》" + bundle.getString("result"));
//                    mTextView.setText(bundle.getString("result"));
//                    //显示
//                    mImageView.setImageBitmap((Bitmap) data.getParcelableExtra("bitmap"));
                }
                break;
        }
    }


    //全部商品 Adapter
    private class AllproductAdapter extends BaseAdapter {
        private List<AllProductResp.ResultEntity.DataEntity> all_productList;

        public AllproductAdapter(List<AllProductResp.ResultEntity.DataEntity> info) {
            if (info == null) {
                info = new ArrayList<AllProductResp.ResultEntity.DataEntity>();
            }
            all_productList = info;
        }

        @Override
        public int getCount() {
            return all_productList.size();
        }

        @Override
        public AllProductResp.ResultEntity.DataEntity getItem(int position) {
            return all_productList.get(position);
        }

        @Override
        public long getItemId(int position) {
            return position;
        }

        @Override
        public View getView(final int position, View convertView, ViewGroup parent) {
            ViewHolder vh = null;
            if (convertView == null) {
                convertView = LayoutInflater.from(mActivity).inflate(R.layout.allproduct_gridview, null);
                vh = new ViewHolder();
                vh.img_all_product = (ImageView) convertView.findViewById(R.id.img_all_product);
                vh.tv_search_name= (TextView) convertView.findViewById(R.id.tv_search_name);
                vh.tv_search_describe = (TextView) convertView.findViewById(R.id.tv_search_describe);
                vh.tv_search_price = (TextView) convertView.findViewById(R.id.tv_search_price);
                vh.tv_search_original_price = (TextView) convertView.findViewById(R.id.tv_search_original_price);
                vh.tv_search_payment_number = (TextView) convertView.findViewById(R.id.tv_search_payment_number);

            } else {
                vh = (ViewHolder) convertView.getTag();
            }
            convertView.setTag(vh);
            convertView.setClickable(true);

            vh.tv_search_name.setText(getItem(position).getName());
            vh.tv_search_describe.setText(getItem(position).getDescription());
            vh.tv_search_price.setText("￥ "+getItem(position).getPrice());
            vh.tv_search_payment_number.setText(getItem(position).getSales() + "人付款");
            ImageLoader.getInstance().displayImage(getItem(position).getList_thumb(), vh.img_all_product, displayImageOptions);
            convertView.setOnClickListener(new View.OnClickListener() {
                @Override
                public void onClick(View view) {
                    Intent intent = new Intent(mActivity, ProductDetails.class);
                    intent.putExtra("id", getItem(position).getId() + "");
                    startActivity(intent);
                }
            });

            return convertView;
        }

        class ViewHolder {
            private ImageView img_all_product;
            private TextView tv_search_name,tv_search_describe,tv_search_price,tv_search_original_price,tv_search_payment_number;
        }
    }


    /**
     * Banner适配器
     */
    public class BannerAdapter extends BannerPagerAdapter {
        private Context mContext;
        private List<BannerInfoResp.ResultEntity.DataEntity> data;

        public BannerAdapter(Context context, List data) {
            super(context, data);
            mContext = context;
            this.data = data;
        }

        @Override
        public View setView(int position) {
            View v = LayoutInflater.from(mContext).inflate(R.layout.homepager_banner_img, null);
            ImageView iv = (ImageView) v.findViewById(R.id.banner_img);
            ImageLoader.getInstance().displayImage(data.get(position).getThumb(), iv, displayImageOptions);
            return v;
        }
    }

    //获取活动类型
    private void GetActivityType() {
        CustomProgressDialog.createDialog(mActivity).show();
        ActivitytypeReq req = new ActivitytypeReq();
        req.setTime(System.currentTimeMillis() + "");

        RequestParams params = new RequestParams();
        params.put("secret", req.getSecret());

        Async_http_get.get(Const.COMMON_ADDRESS + req.urlString(), params, new JsonHttpResponseHandler() {
            @Override
            public void onSuccess(int statusCode, Header[] headers, JSONObject response) {
                super.onSuccess(statusCode, headers, response);
                CustomProgressDialog.Dismiss();
                Log.e("ssss", "11111");
                String errno = response.optString("errno");
                String errmsg = response.optString("errmsg");

                if (errno.equals("000")) {
                    Log.e("ssss", "22222");
                    ActivitytypeResp resp = GsonImpl.get().toObject(response.toString(), ActivitytypeResp.class);
                    List<ActivitytypeResp.ResultEntity.DataEntity> typelist = new ArrayList<ActivitytypeResp.ResultEntity.DataEntity>();
                    typelist.addAll(resp.getResult().getData());
                    hot_Selected_id = typelist.get(2).getId();
                    hot_product_id = typelist.get(1).getId();
                    bargain_product_id = typelist.get(3).getId();
                    all_product_id = typelist.get(0).getId();
                    Log.e("ssss1", "1111==>" + bargain_product_id);
                    Log.e("ssss1", "2222==>" + hot_Selected_id);
                    Log.e("ssss1", "3333==>" + hot_product_id);


                } else {
//                    CommonUtil.showToast(mActivity, errmsg);
                    Log.e("ssss", "33333");

                }
            }

            @Override
            public void onFailure(int statusCode, Header[] headers, String responseString, Throwable throwable) {
                super.onFailure(statusCode, headers, responseString, throwable);
                Log.e("ssss", "444444");
                CustomProgressDialog.Dismiss();
                CommonUtil.showToast(mActivity, "网络连接失败1111");
            }
        });
    }

    //获取banner广告栏（viewpager）
    private void LoadBanner() {
        CustomProgressDialog.createDialog(mActivity);
        HomePageBannerReq req = new HomePageBannerReq();
        req.setType("1");
        req.setPage("1");
        req.setPage_size("6");

        RequestParams params = new RequestParams();


        if (sharedPreferencesUtil.getAccessToken() != null) {
            params.put("token", sharedPreferencesUtil.getAccessToken());
        }
        params.put("secret", req.getSecret());
        Async_http_get.get(Const.COMMON_ADDRESS + req.urlString(), params, new JsonHttpResponseHandler() {
            @Override
            public void onSuccess(int statusCode, Header[] headers, JSONObject response) {
                super.onSuccess(statusCode, headers, response);
//                CustomProgressDialog.Dismiss();
                homepage_ptrScrollview.onRefreshComplete();
                Log.e(ssss, "获取banner数据");
//                Log.e("url", "viewpager_ad_banner_json==" + response);
                String errno = response.optString("errno");
                String errmsg = response.optString("errmsg");
                if (errno.equals("000")) {
                    BannerInfoResp info = GsonImpl.get().toObject(response.toString(), BannerInfoResp.class);
                    bannerList.clear();
                    bannerList.addAll(info.getResult().getData());
                    initbanner();
                } else {
                    CustomProgressDialog.Dismiss();

                }
            }

            @Override
            public void onFailure(int statusCode, Header[] headers, String responseString, Throwable throwable) {
                super.onFailure(statusCode, headers, responseString, throwable);
            }
        });
    }

    //获取通告栏广告（2个）
    private void LoadNoticeAD() {
//        CustomProgressDialog.createDialog(mActivity).show();
        HomePageBannerReq req = new HomePageBannerReq();
        req.setType("3");
        req.setPage("1");
        req.setPage_size("10");

        RequestParams params = new RequestParams();

        if (sharedPreferencesUtil.getAccessToken() != null) {
            params.put("token", sharedPreferencesUtil.getAccessToken());
        }
        params.put("secret", req.getSecret());
        Async_http_get.get(Const.COMMON_ADDRESS + req.urlString(), params, new JsonHttpResponseHandler() {
            @Override
            public void onSuccess(int statusCode, Header[] headers, JSONObject response) {
                super.onSuccess(statusCode, headers, response);
//                CustomProgressDialog.Dismiss();
                Log.e("ssss", "获取两个通告栏数据");
//                Log.e("url", "viewpager_ad_banner_json1111==" + response);
                String errno = response.optString("errno");
                String errmsg = response.optString("errmsg");
                if (errno.equals("000")) {
                    NoticeADResp resp = GsonImpl.get().toObject(response.toString(), NoticeADResp.class);

                    tonglanUrl1 = resp.getResult().getData().get(0).getThumb();
                    tonglanUrl2 = resp.getResult().getData().get(1).getThumb();
                    Log.e("ssss", "获取两个通告栏数据:tonglanUrl1=="+tonglanUrl1+"  tonglanUrl2=="+tonglanUrl2);
                    ImageLoader.getInstance().displayImage(tonglanUrl1, img_new_product_ad, displayImageOptions_tonggaolan);
                    ImageLoader.getInstance().displayImage(tonglanUrl2, img_hot_product_ad, displayImageOptions_tonggaolan);

                } else {
                    CommonUtil.showToast(mActivity, errmsg);

                }
                LoadFangGeAD();
            }

            @Override
            public void onFailure(int statusCode, Header[] headers, String responseString, Throwable throwable) {
                super.onFailure(statusCode, headers, responseString, throwable);
                CommonUtil.showToast(mActivity, "网络连接失败2222");
            }
        });
    }

    //获取方格（5个图片）
    private void LoadFangGeAD() {
//        CustomProgressDialog.createDialog(mActivity).show();
        HomePageBannerReq req = new HomePageBannerReq();
        req.setType("4");
        req.setPage("1");
        req.setPage_size("6");

        RequestParams params = new RequestParams();

        if (sharedPreferencesUtil.getAccessToken() != null) {
            params.put("token", sharedPreferencesUtil.getAccessToken());
        }
        params.put("secret", req.getSecret());
        Async_http_get.get(Const.COMMON_ADDRESS + req.urlString(), params, new JsonHttpResponseHandler() {
            @Override
            public void onSuccess(int statusCode, Header[] headers, JSONObject response) {
                super.onSuccess(statusCode, headers, response);
                CustomProgressDialog.Dismiss();
                Log.e("ssss", "获取方格数据");
//                Log.e("url", "viewpager_ad_banner_json1111==" + response);
                String errno = response.optString("errno");
                String errmsg = response.optString("errmsg");
                if (errno.equals("000")) {
                    FangGeResp resp = GsonImpl.get().toObject(response.toString(), FangGeResp.class);
                    fanggeUrl1 = resp.getResult().getData().get(0).getUrl();
                    fanggeUrl2 = resp.getResult().getData().get(1).getUrl();
                    fanggeUrl3 = resp.getResult().getData().get(2).getUrl();
                    fanggeUrl4 = resp.getResult().getData().get(3).getUrl();
                    fanggeUrl5 = resp.getResult().getData().get(4).getUrl();

                    fanggeId1 = resp.getResult().getData().get(0).getProduct_id();
                    fanggeId2 = resp.getResult().getData().get(1).getProduct_id();
                    fanggeId3 = resp.getResult().getData().get(2).getProduct_id();
                    fanggeId4 = resp.getResult().getData().get(3).getProduct_id();
                    fanggeId5 = resp.getResult().getData().get(4).getProduct_id();

                    ImageLoader.getInstance().displayImage(resp.getResult().getData().get(0).getThumb(), img_top_product1, displayImageOptions);
                    ImageLoader.getInstance().displayImage(resp.getResult().getData().get(1).getThumb(), img_top_product2, displayImageOptions);
                    ImageLoader.getInstance().displayImage(resp.getResult().getData().get(2).getThumb(), img_top_product3, displayImageOptions);
                    ImageLoader.getInstance().displayImage(resp.getResult().getData().get(3).getThumb(), img_top_product4, displayImageOptions);
                    ImageLoader.getInstance().displayImage(resp.getResult().getData().get(4).getThumb(), img_top_product5, displayImageOptions);
                } else {
                }
            }

            @Override
            public void onFailure(int statusCode, Header[] headers, String responseString, Throwable throwable) {
                super.onFailure(statusCode, headers, responseString, throwable);
            }
        });
    }


}
